home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group97a.txt
/
000119_icon-group-sender _Sat Apr 19 08:08:45 1997.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
3KB
Received: from kingfisher.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Mon, 21 Apr 1997 09:27:46 MST
Received: by kingfisher.CS.Arizona.EDU; (5.65v3.2/1.1.8.2/08Nov94-0446PM)
id AA04801; Mon, 21 Apr 1997 09:27:45 -0700
Message-Id: <3358C3DD.23EE@airmail.net>
Date: Sat, 19 Apr 1997 08:08:45 -0500
From: Nathanael Graham <nathang@airmail.net>
X-Mailer: Mozilla 2.01 (Win95; U)
Mime-Version: 1.0
To: icon-group@cs.arizona.edu
Subject: Comments on Icon Routine
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 2775
To fellow Iconers:
This week at work I wanted to take documents created by MS-Word or
WordPerfect and break down the 80+ character lines into lines of no more
than 80 characters and I figured that this would be a perfect use for
Icon. The routine did not take too long to code and, at the suggestion
of a fellow worker, I generalized it to allow for lines of any specified
length. Assuming the Icon routine is called truncate.icn/truncate.exe,
one would type the following on the command line:
truncate infile.txt outfile.txt 80
This would:
. Read in each record from infile.txt
. After deleting leading spaces, it would write the record to
outfile.txt, if the record length was 80 or less
. If the record length was greater than 80, then it would "break up"
the record on spaces, scanning for them from position 81 and going
backwards. Once it found the space, it would write from the
beginning of the record to the space and repeat the same
algorithm starting with what was left of the record after the
space. If no space was found in any record or piece thereof of
length 80 or more, then the first 80 characters would be written,
and the rest of the record would be handled per above.
I've been writing Icon utilities for a number of years off and on,
but still consider myself somewhat of a beginner. I am posting this
routine to the Icon list in the hopes that more experienced
practicioners of the language will point out ways in which I can more
fully utilize the unique strengths of Icon.
Thanks for your help in advance.
Steve Graham
========================================================================
procedure main(files)
in := open(files[1],"r") | stop("Problem opening " || files[1])
out := open(files[2],"w") | stop("Problem opening " || files[2])
rmargin := files[3]
while line := read(in) do {
if *(line := ltrim(line)) < (rmargin + 1)
then write(out,line)
else {
while *(line := ltrim(line)) > rmargin do {
if line[rmargin+1] == " "
then {
write(out,line[1:rmargin + 1])
line[1:rmargin + 1] := ""
}
else {
i := upto(" ",reverse(line[1:rmargin + 1])) |
0
write(out,line[1:(rmargin + 1)-i])
line[1:(rmargin + 1)-i] := ""
} }
if *line > 0
then write(out,line)
} }
close(out)
close(in)
end
procedure ltrim(txt)
while any(' ',txt) do txt[1] := ""
return txt
end